#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    const map<string, int> digits{
    {"zero", 0},
    {"one", 1},
    {"two", 2},
    {"three", 3},
    {"four", 4},
    {"five", 5},
    {"six", 6},
    {"seven", 7},
    {"eight", 8},
    {"nine", 9},
};


    string line;
    getline(cin, line);
    if (line.back() != ' ') {
        line.push_back(' ');
    }

    vector<string> words;
    string word;
    for (char c : line) {
        if (c == ' ') {
            words.push_back(word);
            word = "";
        } else {
            word.push_back(c);
        }
    }

    if (words.size() != 3 || words[0] == "zero") {
        cout << "Wrong input" << '\n';
        return 0;
    }
    
vector<int> ns;
    for (string word : words) {
        if (digits.find(word) == digits.end()) {
            cout << "Wrong input" << '\n';
            return 0;
        }
        ns.push_back(digits.at(word));
    }
    int n = 100 * ns[0] + 10 * ns[1] + ns[2];
    
int i, j, x, f, per, k, mi, ma;
vector<int> pr;
for (i=100;i<1000;i++){
    f = 1;
    for (x=2;x<i;x++){
        if (i%x == 0){
            f = 0;
            break;
        }
    }
    if (f==1)
        {
        pr.push_back(i);}
}
    for (int j = 0; j<pr.size(); j++)
    {
        per = pr[0];
    }
    
    for (int i = 0; i < pr.size(); i ++)
    {
        if (pr[i] <= n)
        {
            k = i;
            mi = pr[i];
        }
        if (pr[i] >= n)
        {
            ma = pr[k + 1];
        }
    }
    if (n == 100)
        cout << per;
    else
{
    if (abs(n-mi) < abs(n-ma) or abs(n-mi) == abs(n-ma))
    cout << mi;
    
    else 
    {
    if (abs(n-ma) < abs(n-mi))
    cout << ma;
    }
}   
    return 0;
}